package com.qf.shopping.service.impl;

import com.qf.shopping.dao.IOrderDao;
import com.qf.shopping.dao.IOrderDetailDao;
import com.qf.shopping.dao.impl.OrderDaoImpl;
import com.qf.shopping.dao.impl.OrderDetailDaoImpl;
import com.qf.shopping.dto.BackOrder;
import com.qf.shopping.entity.Order;
import com.qf.shopping.entity.OrderDetail;
import com.qf.shopping.service.IBackOrderService;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 三旬
 * @version 1.0  2022/9/24
 */

public class BackOrderServiceImpl  implements IBackOrderService {

    IOrderDao orderDao = new OrderDaoImpl();
    IOrderDetailDao orderDetailDao = new OrderDetailDaoImpl();

    /**
     * 获得后台管理员查看的订单数据
     * @return
     */
    @Override
    public List<BackOrder> getOrderList() {
        //1、获得订单集合
        List<Order> orders = orderDao.selectAll();
        //2、获得订单的详细数据
        List<OrderDetail> orderDetails = orderDetailDao.selectAll();
        //3、整合成一个后台订单数据集合
        List<BackOrder> list = new ArrayList<>();
        //先将商品的详细数据放进后台订单集合中(缺少订单时间和状态)
        for (OrderDetail o :orderDetails){
            BackOrder b = new BackOrder();
            b.setOid(o.getOid());
            b.setPngUrl(o.getPngUrl());
            b.setDes(o.getDes());
            b.setPrice(o.getPrice());
            b.setNums(o.getNums());
            b.setTotal(o.getTotal());
            list.add(b);
        }
        //从订单中获得时间和状态
        for (Order o : orders) {
            for (BackOrder b : list) {
                if(b.getOid().equals(o.getId())){
                    b.setCreateTime(o.getCreateTime().toString());
                    b.setStatu(o.getStatu());
                }
            }
        }

        return list;
    }
}
